package com.nidu.demo.config.executor.query;

import com.alibaba.cola.dto.SingleResponse;
import com.nidu.demo.config.ability.ConfigDomainService;
import com.nidu.demo.config.convertor.ConfigConvertor;
import com.nidu.demo.config.dto.ConfigCO;
import com.nidu.demo.config.gateway.ConfigGateway;
import com.nidu.demo.config.model.Config;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 配置单查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class ConfigSingleQryExe {

    private final ConfigGateway gateway;
    private final ConfigDomainService domainService;
    private final ConfigConvertor convertor;

    public SingleResponse<ConfigCO> execute(Long id) {
        // 1. 校验配置是否存在
        domainService.validateConfig(id);

        // 2. 查询配置
        Config config = gateway.getById(id);

        // 3. 转换为DTO返回
        ConfigCO configCO = convertor.toClientObject(config);

        return SingleResponse.of(configCO);
    }
} 